package com.css.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.css.dao.ICustomerDAO;
import com.css.vo.Customer;

public class CustomerDAO extends HibernateDaoSupport implements ICustomerDAO {

	@Override
	public void save(Customer customer) {
		getHibernateTemplate().save(customer);
	}

	@Override
	public void delete(Customer customer) {
		getHibernateTemplate().delete(customer);
	}

	@Override
	public void update(Customer customer) {
		getHibernateTemplate().update(customer);
	}

	@Override
	public Customer find(String customerName) {
		@SuppressWarnings("unchecked")
		List<Customer> list = getHibernateTemplate().find(
				"from Customer where CustomerName = ?", customerName);
		if (list.size() > 0) {
			return (Customer) list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public List<Customer> findAllCustomer() {
		List<Customer> list = getHibernateTemplate().find("from Customer");
		return list;
	}

	@Override
	public List<Customer> findById(Integer id) {
		List<Customer> list = getHibernateTemplate().find(
				"from Customer where CustomerId = ?", id);
		return list;
	}

}
